package com.errol.batchprocessor.batchprocessor.advisor;

import com.renjia.entity.AbstractImportBatch;
import com.renjia.service.generic.middleware.batchprocessor.abs.AbstractAdvisor;
import com.renjia.service.generic.middleware.batchprocessor.bo.ThreadPoolStatusBO;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractBatchPayload;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractPiecePayload;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractSinglePayload;
import org.springframework.lang.NonNull;

import java.util.List;

/**
 * 批次添加到线程池时的扩展点
 *
 * @author zhang xiao bin
 * @version v1.0
 * @date 2021/02/26
 * @since v5.0.5
 **/
public interface BatchAddAdvisor<IE extends AbstractImportBatch, AT extends Enum<?>, BE, SE, BP extends AbstractBatchPayload<IE, AT, BE, SE>, PP extends AbstractPiecePayload<SE, SP>, SP extends AbstractSinglePayload<SE>>
        extends AbstractAdvisor<AbstractBatchPayload<IE, AT, BE, SE>> {

    /**
     * 批次添加到线程池时执行分片策略
     * 该方法在编辑单一记录时也会使用，因此建议该接口实现 仅 处理分片逻辑
     *
     * @param batchPayload     BP
     * @param threadPoolStatus 线程池状态
     * @return PP list，或 null 表示跳过当前扩展，尝试执行下一个 BatchAdd 扩展进行分片
     */
    List<PP> doSplitOnBatchAdded(@NonNull BP batchPayload, @NonNull ThreadPoolStatusBO threadPoolStatus);
}
